package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.UserFollow;
import com.api.user.service.UserFollowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/03/29.
*/
@PowerEnable(name = "UserFollow",url = "/user/follow")
@Api(value = "UserFollow", tags = {"UserFollow"})
@RestController
@RequestMapping("/user/follow")
public class UserFollowController extends Ctrl{
    @Resource
    private UserFollowService userFollowService;

    @ApiOperation(value = "关注用户", tags = {"UserFollow"}, notes = "关注用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "被关注人的ID", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/add",name="关注用户")
    public Result add(@RequestParam Long userId, Authentication authentication) {
        Long fansId = getAuthUser(authentication).getId();
        userFollowService.add(userId,fansId);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "取消关注", tags = {"UserFollow"}, notes = "取消关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "取消关注人的ID", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/remove",name="取消关注")
    public Result remove(@RequestParam Long userId, Authentication authentication) {
        Long fansId = getAuthUser(authentication).getId();
        userFollowService.remove(userId,fansId);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "我关注的用户/关注我的用户", tags = {"UserFollow"}, notes = "我关注的用户/关注我的用户")
    @PostMapping(value = "/list", name = "我关注的用户/关注我的用户")
    public Result list(@RequestParam Boolean me,
                       @RequestParam(required = false) Long uid,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size, Authentication authentication) {
        Long userId = getAuthUser(authentication).getId();
        return userFollowService.list(me,uid,userId, order, page, size);
    }
}
